package com.winshare.saleAssistant.domain.dto.req;

import com.winshare.saleAssistant.exception.BusinessException;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Objects;

@ApiModel
public class OrganizationUpdateDTO {

    @NotNull(message = "主键不可以为空")
    @Range(min = 1, message = "主键最小从1开始")
    @ApiModelProperty(value = "主键不可以为空")
    private Integer id;

    @NotBlank(message = "机构编码不可以为空")
    @Length(min = 1, max = 45, message = "机构编码长度需要在1-45个字之间")
    @ApiModelProperty(value = "机构编码")
    private String orgCode;

    @NotBlank(message = "机构名称不可以为空")
    @Length(min = 1, max = 100, message = "机构名称长度需要在1-100个字之间")
    @ApiModelProperty(value = "机构名称")
    private String orgName;

    @NotBlank(message = "机构地址不可以为空")
    @Length(min = 1, max = 150, message = "机构地址长度需要在1-150个字之间")
    @ApiModelProperty(value = "机构地址")
    private String orgAddress;

    @NotBlank(message = "机构类型不可以为空")
    @Length(min = 1, max = 40, message = "机构类型长度需要在1-40个字之间，机构类型分为如下4种：业务组织单位，市公司，分公司，其他")
    @ApiModelProperty(value = "=机构类型：业务组织单位，市公司，分公司，其他")
    private String orgType;

    @ApiModelProperty(value = "上级机构编码")
    private String parentOrgCode;

    @ApiModelProperty(value = "上级机构名称")
    private String parentOrgName;

    @ApiModelProperty(value = "上级机构Id")
    private Integer parentOrgId;

    @NotBlank(message = "数据范围/产品范围不可以为空")
    @Length(min = 1, max = 100, message = "数据范围/产品范围长度需要在1-100个字之间")
    @ApiModelProperty(value = "数据范围/产品范围")
    private String dataScope;

    public OrganizationUpdateDTO() {
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getOrgCode() {
        return orgCode;
    }

    public void setOrgCode(String orgCode) {
        this.orgCode = orgCode;
    }

    public String getOrgName() {
        return orgName;
    }

    public void setOrgName(String orgName) {
        this.orgName = orgName;
    }

    public String getOrgAddress() {
        return orgAddress;
    }

    public void setOrgAddress(String orgAddress) {
        this.orgAddress = orgAddress;
    }

    public String getOrgType() {
        return orgType;
    }

    public void setOrgType(String orgType) {
        this.orgType = orgType;
    }

    public String getParentOrgCode() {
        return parentOrgCode;
    }

    public void setParentOrgCode(String parentOrgCode) {
        this.parentOrgCode = parentOrgCode;
    }

    public String getParentOrgName() {
        return parentOrgName;
    }

    public void setParentOrgName(String parentOrgName) {
        this.parentOrgName = parentOrgName;
    }

    public String getDataScope() {
        return dataScope;
    }

    public void setDataScope(String dataScope) {
        this.dataScope = dataScope;
    }

    public Integer getParentOrgId() {
        return parentOrgId;
    }

    public void setParentOrgId(Integer parentOrgId) {
        this.parentOrgId = parentOrgId;
    }

    public void validateOrgType(){
        if(Objects.equals(this.orgType,"业务组织单位")|| Objects.equals(this.orgType,"市公司")
           || Objects.equals(this.orgType,"分公司") || Objects.equals(this.orgType,"其他")) {
            return;
        }
        throw new BusinessException("机构类型只能填写如下四种：业务组织单位，市公司，分公司，其他");
    }
}
